package com.flying.carclub.fragment;

import android.os.Bundle;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cheng.commonlib.loopbander.AutoScrollViewPager;
import com.cheng.commonlib.loopbander.ViewGroupIndicator;
import com.cheng.commonlib.magicrecyclerView.BaseItem;
import com.cheng.commonlib.magicrecyclerView.BaseRecyclerAdapter;
import com.cheng.commonlib.magicrecyclerView.MagicRecyclerView;
import com.flying.carclub.R;
import com.flying.carclub.activity.LoginActivity;
import com.flying.carclub.activity.SignupActivity;
import com.flying.carclub.bean.UserInfoBean;
import com.flying.carclub.modules.home.ArticleAdapter;
import com.flying.carclub.modules.home.HomeTopPagerAdapter;
import com.flying.carclub.modules.home.mvp.ArticleDailyModel;
import com.flying.carclub.modules.home.mvp.ArticleModel;
import com.flying.carclub.modules.home.mvp.TopArticleModel;
import com.flying.carclub.utils.BottomNavigationViewHelper;
import com.flying.carclub.utils.ResponseParser;
import com.flying.carclub.utils.SPUtils;
import com.mob.MobSDK;
import com.review.signature.Review;
import com.stonesun.newssdk.NewsAgent;
import com.stonesun.newssdk.bean.UserInfo;
import com.stonesun.newssdk.fragment.NewsAFragment;
import com.stonesun.newssdk.itf.AppUserItf;

import java.util.ArrayList;

import cn.newssdk.share.Share;

/**
 * A simple {@link Fragment} subclass.
 * Activities that contain this fragment must implement the
 * to handle interaction events.
 * create an instance of this fragment.
 */
public class HomeFragment extends Fragment {

    public HomeFragment() {
        // Required empty public constructor
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view  = inflater.inflate(R.layout.fragment_home, container, false);
        initView(view);
        return view;
    }

    private void initView(View contentView){

//        Review.MD5Review(getActivity(), "com.stonesun.testnewssdk", "37035aa4bdce2495756114e645665c9e");
        NewsAgent.setDebugMode(true);
//        NewsAgent.setPermission(getActivity(),true);//sdk请求权限
        NewsAgent.init(getActivity());
        MobSDK.init(getActivity());
        MobSDK.init(getActivity(),"23ca5632bae6c","0ba7cba7806101967f70b1987460b1de");

        final UserInfoBean userInfoBean = SPUtils.getUserInfo(getActivity());
        if (userInfoBean != null) {
            AppUserItf appUserItf = new AppUserItf() {
                @Override
                public boolean isLogin() {
                    return true;
                }

                @Override
                public UserInfo getUserinfo() {
                    UserInfo userInfo = new UserInfo();
                    userInfo.setUid(userInfoBean.authKey);
                    userInfo.setToken(userInfoBean.authKey);
                    userInfo.setUsericon("");
                    userInfo.setUsername(userInfoBean.username);
                    userInfo.setFrom("QQ");
                    return userInfo;
                }
            };
            NewsAgent.SetUserImpForSDK(appUserItf, LoginActivity.class);
        }else {
            NewsAgent.SetUserImpForSDK(null, LoginActivity.class);
        }
        NewsAgent.createShareCommentViewActivity("资讯详情");
        NewsAgent.setShowShare(new Share(),"资讯详情");
        NewsAgent.createDefaultRecomFragment("默认推荐", "SPOTS-360316", "资讯详情");

        FragmentManager fm = getChildFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        NewsAFragment recomFragment = NewsAgent.getDefaultRecomFragment("默认推荐");
//        recomFragment.search("","文章标题","tt");
        transaction.add(R.id.frame_container, recomFragment).commit();
    }


}
